package com.cd.university.service.impl;

import com.cd.university.controller.form.MessageIdForm;
import com.cd.university.db.mapper.MessageMapper;
import com.cd.university.db.pojo.Message;
import com.cd.university.service.abs.AbstractMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 陈栋
 * @create 2021/11/24 14:14
 */
@Transactional(rollbackFor = Exception.class)
public class DefaultMessageServiceImpl extends AbstractMessage {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public boolean saveRepository(Message message) {
        int row = messageMapper.insertSelective(message);

        if (row < 0) {
            return false;
        }
        return true;
    }

    @Override
    public List<Message> findMessagesByUser(Integer userId) {
        List<Message> messages = messageMapper.searchByUserId(userId);
        return messages;
    }

    @Override
    public int approveRepoMessages(List<MessageIdForm> messageIdList) {
        int row = messageMapper.haveReadByList(messageIdList);
        return row;
    }

    @Override
    public int approveUserMessages(Integer userId) {
        return messageMapper.haveReadByUserId(userId);
    }
}
